<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="perm" uri="/WEB-INF/tld/perm.tld"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<c:set var="imagePath" value="/b2b4shoumei_resources" />
<html>
	<script>
	var ctx = "${ctx}/seller";
	var imagePath = "${imagePath}";
</script>
	<head>
	    <meta charset="utf-8">
	    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	    <title>专场发布编辑</title>
	    <meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
		<meta http-equiv="expires" content="Wed, 26 Feb 209908:21:57 GMT"> 
	    
	<link href="${ctx}/static/css/bootstrap.min.css?v=${static_version}/"
	rel="stylesheet">
	<link
	href="${ctx}/static/css/font-awesome.min.css?v=4.4.0?v=${static_version}/"
	rel="stylesheet">	
	<link href="${ctx}/static/css/style.min.css?v=${static_version}/"
	rel="stylesheet">
    <link href="${ctx}/static/css/common.css?v=${static_version}" rel="stylesheet" />
    
    	<link href="//at.alicdn.com/t/font_9x03jhokyws9vn29.css" rel="stylesheet">
	<!-- 插件样式  -->
	<link href="${ctx}/static/css/plugins/webuploader/webuploader.css" rel="stylesheet" />
	<link href="${ctx}/static/css/plugins/datapicker/datepicker3.css" rel="stylesheet">


	</head>
	<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
	<%--  --%>
	<div class="ibox float-e-margins" style="background: #fff">
		<div class="ibox-title">
                    <h5><small>专场信息</small></h5>
                </div>
        <div class="ibox-content">
		 <form action="" method="post" class="form form-horizontal" id="form-sc-add"> 
			<div class="form-group">
			
						<label class="col-sm-2 control-label">专场类别</label>
					<div class="col-sm-10">
									<div class="col-sm-4 m-l-n">
							<span class="select-box"> <select class="form-control"
								name="typeId" id="typeId">
									<option value="-1">--请选择--</option>
									<c:forEach items="${types}" var="type">
										<option value="${type.C_CODE}"<c:if test="${type.C_CODE==topicMap.type_id}">selected</c:if>>${type.C_NAME}</option>
									</c:forEach>
							</select>
							</span>
								</div>
								</div>
			</div>
			<div class="form-group">			
				<label class="col-sm-2 control-label">专场时间</label>
				<div class="col-sm-10">
									<div class="col-sm-4 m-l-n">
					<input id="start_date" name="start_date" value="${topicMap.start_date }" onclick="new WdatePicker()" class="form-control">
					</div>
					<div class="col-sm-4 m-l-n">
					<select name="hour" id="hour"
						class="form-control">
							<option value="-1">--时间段--</option>
							<c:forEach items="${timeMap}" var="type">
										<option value="${type.key}"<c:if test="${type.key==time}">selected</c:if>>${type.value}</option>
									</c:forEach>
					</select>
						</div>
					</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">专场名称</label>
				<div class="col-sm-10">
						<div class="col-sm-4 m-l-n">		
					<input id="title" class="form-control" name=title value="${topicMap.title}">
			</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">专场图片</label>
				<div class="col-sm-10">
				
				
				<div class="col-sm-2 m-l-n">
							<a id="iconbutton" class="webuploader-container">
							<div class="webuploader-pick"><i class="iconfont icon-plus1"></i></div>
							<div id="rt_rt_1bbnqbnf8haj1eqj19qr15b413dp1">
							<input type="file" name="file" class="webuploader-element-invisible" multiple accept="image/jpg,image/jpeg,image/png">
							</div>
							</a>						
							<div id="fileList_covers" class="uploader-list">
							<img 
								<c:if test="${topicMap.topic_img!=''&&!empty topicMap.topic_img}">src="${topicMap.topic_img}"</c:if>
								alt="" class="margin" id="iconImg" style="height: 100px;">
							</div>
							<br>尺寸：380px *380px<br>格式：PNG						
						</div>

						</div>
				</div>
				
				 
	       <!-- 提交button-->
	       <input type="hidden" name="topicImg" class="input-text" id="covers" value="${topicMap.topic_img}" />
			<input type="hidden" name="topicId" class="input-text" id="topicId" value="${topicMap.topic_id}" />
			<c:if test="${not empty flag }">
			<table
				class="table table-border table-bordered table-hover table-bg table-sort">
				<thead>
					<tr class="text-c">
					<th width="80">ID</th>
						<th width="80">商品名称</th>
						<th>市场价</th>
						<th>销售价</th>
						<th>库存</th>
						<th>图片</th>
						<th width="120">操作</th>
					</tr>
				</thead>
					<tbody id="tb">
					<c:choose>
						<c:when test="${empty goodList}">
							<tr class="text-c">
								<td colspan="7">暂无数据</td>
							</tr>
						</c:when>
						<c:otherwise>
							<c:forEach items="${goodList}" var="var">
								<tr class="text-c">
								    <td>${var.ID }</td>
									<td>${var.NAME}</td> 
									<td>${var.MKT_PRICE}</td> 	
									<td>${var.PRICE}</td> 	
									<td>${var.STORE}</td> 	
									<td><img src="${var.IMAGE}"  style="height:30px"/></td>
									<td class="td-manage">
										<%-- <a class="btn btn-success" onclick="goods_add('添加产品','${ctx}/seller/goods-add-pre?isZiYing=${isZiYing}')" href="javascript:;"> 添加
		</a> --%>
										<a onClick="t_good_delete(this,'${var.TOPIC_LINK_ID}')" class="btn btn-warning " type="button" href="javascript:void(0);" title="删除">删除</a></td>
								</tr>
							</c:forEach>
						</c:otherwise>
					</c:choose>

				</tbody>
			</table>
			</c:if>
			<div class="form-group">
					<div class="col-sm-4 col-sm-offset-2">
			<button onClick="sp_upd_submit();" id="save-btn"
				class="btn btn-primary" type="" style="">
				 保存并提交
			</button>
				</div>
				</div>
	       <!--提交buttonend-->
				
			</div>
	       
	      
	       
	       
			</form>
		 </div>
					
			</div>
</div>
</div>
</div>
</div>
<script src="${ctx}/static/js/jquery.min.js?v=${static_version}"></script>
<script src="${ctx}/static/js/bootstrap.min.js?v=${static_version}"></script>

<script
src="${ctx}/static/js/plugins/webuploader/webuploader.min.js?v=${static_version}"></script>

<script src="${ctx}/static/js/My97DatePicker/WdatePicker.js?v=${static_version}"></script>
<script src="${ctx}/static/js/plugins/layer/layer.js?v=${static_version}"></script>

<script type="text/javascript">
         
    /*删除*/
		function t_good_delete(obj,id){
			layer.confirm('确认删除？', {
				btn: ['确认','取消'], 
				shade: false
			},
			function(){
				$.ajax({
					type : "POST",
					url : "${ctx}/seller/topic-goods-delete",
					data : {topicLinkId:id},
					error : function() {
						layer.msg('操作失败', {
							icon : 5,
							time : 1000
						});
					},
					success : function(msg) {
						layer.msg('已删除 ' + msg.information, {
							icon : 6,
							time : 1000
						});
						  location.reload();
					}
				});
			}, function() {
				layer.msg('未删除', {
					icon : 5,
					time : 1000
				});
			});
		} 
	
				$(document)
	.ready(
		function() {
			var $list_covers = $('#fileList_covers'), $list_resources = $('#fileList_resources'), ratio = window.devicePixelRatio || 1, thumbnailWidth = 100 * ratio, thumbnailHeight = 100 * ratio, uploader_resources, uploader_covers;

			/*图片上传*/
			uploader_covers = WebUploader
			.create({
				auto : true,
				swf : '${ctx}/static/plugins/webuploader/0.1.5/Uploader.swf',
				server : '${ctx}/file/uploadPic',
				pick : '#iconbutton',
				accept : {
					title : 'Images',
					extensions : 'gif,jpg,jpeg,bmp,png',
					mimeTypes : 'image/jpg,image/jpeg,image/png'
				}
			});

			uploader_covers
			.on(
				'fileQueued',
				function(file) {
					var $li = $('<div id="' + file.id + '" class="file-item thumbnail">'
						+ '<img>'
						+ '<div class="info">'
						+ file.name
						+ '</div>'
						+ '</div>'), $img = $li
					.find('img');

					$list_covers.html($li);
					uploader_covers
					.makeThumb(
						file,
						function(error,
							src) {
							if (error) {
								$img
								.replaceWith('<span>不能预览</span>');
								return;
							}

							$img
							.attr(
								'src',
								src);
						},
						thumbnailWidth,
						thumbnailHeight);
				});

			uploader_covers.on('uploadSuccess', function(file,
				response) {
				$('#' + file.id).addClass('upload-state-done');
				$("#covers").val(response.datas);
			});

			uploader_covers.on('uploadError', function(file) {
				var $li = $('#' + file.id), $error = $li
				.find('div.error');
				if (!$error.length) {
					$error = $('<div class="error"></div>')
					.appendTo($li);
				}

				$error.text('上传失败');
			});

			uploader_covers.on('uploadComplete',
				function(file) {
					$('#' + file.id).find('.progress')
					.remove();
				});

		});
				
	function edittext() {
		$("#eg").addClass("no-padding");
		$(".click2edit").summernote({
			lang : "zh-CN",
			focus : true
		})
	};
	
	function savetext() {
		$("#eg").removeClass("no-padding");
		var aHTML = $(".click2edit").code();
		$(".click2edit").destroy();
		alert(aHTML);
	};

	function save() {
		$.ajax({
			type : "post",
			url : "${ctx}/bonus-add",
			data : $("#member_table_form").serialize(),
			error: function (jqXHR, textStatus, errorThrown) {
				alert("系统异常");
			},
			success : function(msg) {
				var info = eval('(' + msg + ')');
				if (info.error == '0000') {
					location.href = "${ctx}/createadvertorder?advertid="+info.datas;
				} else {
					alert(info.information);
				}
			}
		})
	}
	function sp_upd_submit(){
		 var cols="";  
	
		 $("#tb tr").each(function(){     
			 var text = $(this).children("td:first").text();      
			 cols+=text+",";   
		 });
			 cols=cols.length>0?cols.substring(0,cols.length-1):"";    
			 var typeId=$("#typeId").val();
			 var hour=$("#hour").val();
			 var title=$("#title").val();
			 var topicImg=$("#covers").val();
			 var start_date=$("#start_date").val();
			 var topicId=$("#topicId").val();
			 var entId=$("#entId").val();
			 var discount=$("#discount").val();
			 if(title == ""){
				    alert("专场不能为空！");
				    return false;
				}
			 
			 if(topicImg == ""){
				    alert("请上传专场图片！");
				    return false;
				}
			
			 $.ajax({
					type:"post",
					async:false,
					url:"${ctx}/seller/addSpeicalChang",
					data : {typeId:typeId,hour:hour,title:title,topicImg:topicImg,start_date:start_date,topicId:topicId,goodsStr:cols,entId:entId,discount:discount},
					success : function(msg){
						//window.navigate("/goods/speChang/speicalChang_add.jsp"); 
						location.href ="${ctx}/seller/speChangList";
						alert("添加成功");
						/* var index = parent.layer.getFrameIndex(window.name);
						if (index){//关闭弹出层
							parent.location.href ="${ctx}/seller/speChangList"; 
							parent.location.reload(true);
							parent.layer.close(index);
						}else{//单独的页面
							//location.href ="${ctx}/seller/speChangList"; 
							window.navigate("/goods/speChang/speicalChang_add.jsp"); 
						} */
					}
					});
				}
				/*添加商品*/
		function goods_add(title,url){
			var index = layer.open({
				type: 2,
				title: title,
				content: url
			});
			layer.full(index);
		} 			
 </script>

</body>
</html>